from typing import Optional, List

from fastapi import APIRouter
from tortoise.expressions import Q

from core import curd
from models import Schedule
from scheams import Schedule_Pydantic, BaseResponse, ScheduleIn_Pydantic, FailureResponse, SuccessResponse

schedule = APIRouter()


@schedule.post("/create", summary="创建计划表", response_model=BaseResponse)
async def create_schedule(schedule_form: List[ScheduleIn_Pydantic]):
    return await curd.create_list(Schedule, schedule_form)


@schedule.delete("/delete", summary="删除计划表", response_model=BaseResponse)
async def delete_schedule(schedule_id: int):
    return await curd.delete_by_plan_id(Schedule, Schedule_Pydantic, Q(schedule_id=schedule_id))


@schedule.put("/update", summary="更新计划表", response_model=BaseResponse)
async def update_schedule(schedule_id: int, schedule_form: ScheduleIn_Pydantic):
    return await curd.update_list_by_plan_id(Schedule, Schedule_Pydantic, schedule_form, Q(schedule_id=schedule_id))


@schedule.get("/read", summary="读取计划表", response_model=BaseResponse)
async def get_schedule(schedule_id: int):
    return await curd.get_list_by_id(Schedule, Schedule_Pydantic, Q(schedule_id=schedule_id))


@schedule.get("/list", summary="读取计划表列表", response_model=BaseResponse)
async def get_schedule_list(limit: Optional[int] = 0, page: Optional[int] = 0):
    return await curd.get_list(Schedule, Schedule_Pydantic, page, limit)
